package com.wsx.rpc.http.controller;

import com.wsx.rpc.api.ApiRequest;
import com.wsx.rpc.api.ApiResponse;
import com.wsx.rpc.api.ApiService;
///import com.wsx.rpc.dubbo.plug.SwitchService;
import com.wsx.rpc.http.cloud.CloudMesticService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wangshuaixin
 * @Title: com.wsx.rpc.http.controller.HttpController
 * @Description: TODO
 * @date 2018/10/30
 */
@RestController
@RequestMapping("/http")
public class HttpController {

    @Autowired
    private CloudMesticService cloudMesticService;

    @Autowired
    private ApiService apiService;


    @RequestMapping(
            value = "/cloud/{name}",
            method = {RequestMethod.GET}
    )
    public ApiResponse cloud(@PathVariable("name") String name) {
        ApiRequest apiRequest = ApiRequest.build();
        apiRequest.setName(name);
        apiRequest.getList().add("hello");
        apiRequest.getMap().put("hello", "world");
        return cloudMesticService.cloud(apiRequest);
    }


    @RequestMapping(
            value = "/dubbo/{name}",
            method = {RequestMethod.GET}
    )
    public ApiResponse dubbo(@PathVariable("name") String name) {
        ApiRequest apiRequest = ApiRequest.build();
        apiRequest.setName(name);
        apiRequest.getList().add("dubbo");
        apiRequest.getMap().put("dubbo", "world");
        ///SwitchService.setSwitch("1@127.0.0.1:23098,192.168.40.9:23098");
        ApiResponse response = apiService.exec(apiRequest);
        ///SwitchService.complate();
        return response;
    }
}
